#define  _CRT_SECURE_NO_WARNINGS
#include<stdlib.h>
#include<stdio.h>
char* replaceSpace(char* s) {
    char* ret = (char*)malloc(strlen(s) * 3 + 1);
    char* new = ret;
    while (*s != '\0')
    {
        if (*s != ' ')
        {
            *new = *s;
            new++;
        }
        else
        {
            *new = '%';
            new++;
            *new = '2';
            new++;
            *new = '0';
            new++;
        }
        ++s;
    }
    *new = '\0';

    return ret;
}
char* replaceSpace2(char* s) {
    int lenth = 0;
    int num = 0;
    char* q = s;
    while (*q)
    {
        if (*q == ' ')
        {
            ++num;
        }
        lenth++;
        q++;
    }
    int newlenth = lenth + num*2+1;
    char* arr = (char*)realloc(s,newlenth);
    q = arr;
    char* p = arr + newlenth-1;
    while (p!=q)
    {
        if (*q != ' ')
        {
            *p = *q;
             p--;
        }
        else
        {
            *p = '0';
            p--;
            *p = '2';
            p--;
            *p = '%';
            p--;

        }
        q--;
    }
    return arr;
}
#include<assert.h>


void reverse(char* left, char* right) {
    assert(left && right);
    while (left < right) {
        char temp = *left;
        *left = *right;
        *right = temp;
        left++;
        right--;
    }

}
char* reverseLeftWords(char* s, int n) {
    int lenth = strlen(s);
    reverse(s, s + n - 1);
    reverse(s + n , s + lenth - 1);
    reverse(s, s + lenth - 1);
    return s;

}

int main()
{
    char* s = "abcdefg";
   char* new = reverseLeftWords(s,3);
   printf("%s", new);
}